<?
include("../lib/config.php");
$username 	= $HTTP_GET_VARS['u'];
$op			= $HTTP_GET_VARS['op'];

if($op == "edit"){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("SELECT * FROM S_User WHERE username='$username' ",$conn);
	$row	= mssql_fetch_array($query);
	$readonly = "readonly";
}
else{
	$Faction = "../lib/save.php";
	$Vbutton = "Simpan";
	$readonly = "";
}

include("../header.php");
?>
<script type="text/javascript" src="../js/selector.js"></script>
<script type="text/javascript">
function setSelectOptions(the_form, the_select, do_check)
{
    var selectObject = document.forms[the_form].elements[the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = do_check;
    } // end for

    return true;
	the_form.submit();
} 
</script>

<script type="text/javascript">
	function Validate(){
		if(document.F.username.value == "")
		{
			alert("Field : Username tidak boleh kosong ...");
			document.F.username.focus();
			return false;
		}
		<?
		if($op == "edit")
		{
		}
		else{
		?>
		if(document.F.password.value == "")
		{
			alert("Field : Password tidak boleh kosong ...");
			document.F.password.focus();
			return false;
		}
		<?
		}
		?>
		if(document.F.group_code.value == "")
		{
			alert("Field : Group User tidak boleh kosong ...");
			document.F.group_code.focus();
			return false;
		}
		
		document.F.submit();
		
	}
</script>
</head>
<table width="93%" class="table_indent2" class="no_border">
 <tr>
  <td colspan="2">
	<table width="100%" style="border:none;">
	<tr>
	 <td colspan="2" class="line_bottom">&nbsp;&nbsp;<b>TABEL USER</b></td>
	</tr>
	<tr>
	</table>
  </td>
 </tr>
 <tr>
  <td>
  <?
	if($op == "edit"){
		$value="$row[username]";
	}
	else{
		$value="";			
	}
  ?>
  <form name="F" action="<?=$Faction?>" method="post">
     <table cellspacing="1" width="100%">
      <tr>
       <td colspan="2">
       <fieldset><legend>Buat Single User</legend>
		<table>
         <tr>
          <td width="200">Username</td>
          <td><input type="text" name="username" value="<?=$value?>" <?=$readonly?> /> <span class="required">*</span></td>
         </tr>
		 <?
		 	if($op == "edit"){
			}
			else
			{
		 ?>
         <tr>
          <td>Password</td>
          <td><input type="password" name="password" value="<?=$row[password]?>"  /> <span class="required">*</span></td>
         </tr>
         <?
		 	}
		 ?>
		 <tr>
          <td>Group User</td>
          <td>
           <select name="group_code">
		   <?
		   // get group id from user
		   $sss = mssql_query("SELECT group_id, group_name FROM S_User_Group A, S_User B WHERE A.group_id=B.groupid AND username='$username'",$conn);
		   $rrr = mssql_fetch_array($sss);
		   echo"<option value='$rrr[0]'>$rrr[group_name]</option>";
		   ?>
            <option value="">--pilih group--</option>
            <?
            	$sgr = mssql_query("SELECT * FROM S_User_Group ORDER BY group_name",$conn);
				while($row = mssql_fetch_array($sgr)){
					echo"
						<option value='$row[group_id]'>$row[group_name]</option>
					";
				}
			?>
           </select> <span class="required">*</span>
          </td>
         </tr>
         <tr>
          <td>&nbsp;</td>
          <td>
          <input type="hidden" name="cat" value="add_user" />
          <input type="button" class="button" value="Batal" onclick="Javascript:history.back();" /><input type="button" class="button" value="<?=$Vbutton?>" onclick="Validate();" /> </td>
         </tr>
        </table>
       </fieldset>
       </td>
      </tr>
     </table>
     </form>
  </td>
</tr>
<tr>
 <td>
    		<fieldset class="fieldset">
				<legend class="legend">Buat Multiple User</legend>
<form action="../lib/save.php" method="post" name="F2">
				<table border="0" style="position:relative; left:80px;" cellpadding="4" cellspacing="1">
				 <tr>
      			<TD valign="top" colspan="3">
				<table width="100%">
				<tr>
                 <td colspan="3">
           Pilih Group User: <select name="group_code">
		   <?
		   // get group id from user
		   $sss = mssql_query("SELECT group_id, group_name FROM S_User_Group A, S_User B WHERE A.group_id=B.groupid AND username='$username'",$conn);
		   $rrr = mssql_fetch_array($sss);
		   echo"<option value='$rrr[0]'>$rrr[group_name]</option>";
		   ?>
            <option value="">--pilih group--</option>
            <?
            	$sgr = mssql_query("SELECT * FROM S_User_Group ORDER BY group_name",$conn);
				while($row = mssql_fetch_array($sgr)){
					echo"
						<option value='$row[group_id]'>$row[group_name]</option>
					";
				}
			?>
           </select> <span class="required">*</span>                 
                 </td>
                </tr>
                </tr>
				<tr>
				<td>Daftar Pegawai (Keseluruhan) :<br>
	  <?
	//$query=mssql_query("select nik,nama from karyawan order by nama asc",$conn);
	$query=mssql_query("select nik,nama from VLatestKarir WHERE Jenis NOT IN ('U','H') order by nama asc",$conn);
	echo"<select multiple='yes' name='sel1[]' class='border_text' style=\"width:200px; height:200px; background-color: #EFEFF8;\">";
	while($row=mssql_fetch_array($query))
	{
		echo"<option value='$row[0]'>$row[0] - $row[1]</option>";
	}
	echo"</select>";
	?>
 	  			</td>
      			<td valign="middle">
	  <INPUT onClick="moveOptions(this.form.elements['sel1[]'], this.form.elements['sel2[]']);" type=button value="->" class="button"><BR>
	  <INPUT onClick="moveOptions(this.form.elements['sel2[]'], this.form.elements['sel1[]']);" type=button value="<-" class="button"> 
      			</td>
      			<td>Hasil Pemilihan Pegawai :<br>
	  <SELECT multiple="yes" size="10" name="sel2[]" style="width:200px; height:200px; background-color: #EFEFF8;" class="border_text">   	
	  </SELECT> 
		  		</td>
		  		</tr>
				</table>
				</TD>
				</tr>
                <tr>
                 <td align="right">
                 <input type="hidden" name="cat" value="multiple_user" />
                 <input type="reset" value="Batal" class="button" onclick="Javascript:history.back();" />
                 <input type="submit" value="Buat User" class="button" onClick="setSelectOptions('F2', 'sel2[]', true);" /></td>
                </tr>
				</table>
                </form>
			</fieldset>
 </td>
</tr>
</table>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>